package ch.ethz.group3.myalbum.client;

import com.reveregroup.gwt.imagepreloader.FitImage;
import com.reveregroup.gwt.imagepreloader.FitImageLoadEvent;
import com.reveregroup.gwt.imagepreloader.FitImageLoadHandler;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.layout.HLayout;

public class ImageOnlyWindow extends Window {
	private HLayout container;
	private FitImage aimage;
	
	public ImageOnlyWindow() {
		setTitle("Image");
		setWidth("80%");
		setHeight("80%");
		setLayoutAlign(Alignment.LEFT);
		setShowModalMask(true);
		setIsModal(true);
		setShowMinimizeButton(false);
		setShowResizer(false);
		setShowCloseButton(true);
		setCanDragReposition(false);
		hideContextMenu();
		centerInPage();
		
		container = new HLayout();
		container.setWidth("100%");
		container.setHeight("100%");
		container.setStyleName("cacca");
		container.setLayoutAlign(Alignment.CENTER);
		container.setAlign(Alignment.CENTER);
		container.setLayoutAlign(VerticalAlignment.CENTER);
		
		addItem(container);
	}
	
	public void showImage(final ImageTileRecord image) {
		setTitle(image.getAttributeAsString("name"));
		container.removeMembers(container.getMembers());
		
		aimage = new FitImage();
//		aimage.setVisible(false);
		aimage.addFitImageLoadHandler(new FitImageLoadHandler() {
		    public void imageLoaded(FitImageLoadEvent event) {  
		    	 if (!event.isLoadFailed()) {
		    		 container.addMember(aimage);
		    	 }
		    }
		});
		aimage.setMaxSize(container.getWidth()-100, container.getHeight()-100);
		aimage.setUrl(image.getAttributeAsString("imageUrl"));
		
	}

}
